<template>    
    <el-container class="home">  
      <el-header>
        <div class="head_left">
          <img src="~assets/img/heima.png" alt="">
          <span>电商后台管理系统</span>
        </div>
        <div class="head_right">
          <el-button type="info" @click="logout">退出</el-button>
        </div>
      </el-header>
      <el-container>
        <el-aside :width="isZhedie? '64px': '200px'">

          <!-- 折叠按钮 -->
          <div class="zhedie" @click="zhedie">|||</div>

          <el-menu
            background-color="#272b35"
            text-color="#fff"
            active-text-color="#3a9afc"
            unique-opened
            :collapse="isZhedie"
            :collapse-transition="false"
            :router="true"
            :default-active="$route.path"
            >
            <!-- 主菜单 -->
            <el-submenu :index="item.id+''" v-for="item in menulist" :key="item.id">
              <template #title>
                <i :class="iconlist[item.id]"></i>
                <span class="menuitem">{{item.authName}}</span>
              </template>
              <!-- 子菜单 -->
              <el-menu-item :index="'/'+item2.path" v-for="item2 in item.children" :key="item2.id">
                <template #title>
                  <i class="el-icon-menu"></i>
                  <span>{{item2.authName}}</span>
                </template>
              </el-menu-item>

            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
</template>

<script>
export default {
  name: "Home",
  data(){
    return {
      menulist: null,
      iconlist: {
        "125": "iconfont icon-users",
        "103": "iconfont icon-tijikongjian",
        "101": "iconfont icon-shangpin",
        "102": "iconfont icon-danju",
        "145": "iconfont icon-baobiao",
      },
      isZhedie: false,
    }
  },

  created() {
    this.menulist = this.getmeunlist()
  },
  methods: {
    logout(){
      window.sessionStorage.clear();
      this.$router.push("/login");
      this.$message.error("退出成功")
    },
    getmeunlist(){
      this.$http.get("/menus").then(res=>{
        this.menulist = res.data.data;
        this.$message.success(res.data.meta.msg);
        // console.log(this.menulist);
      })
    },
    zhedie(){
      this.isZhedie = !this.isZhedie;
    }

  }
}
</script>


<style scpoed>
  .home{
    background-color: #eaedf2;
    height: 100%;
  }

  .el-header{
    display: flex;
    justify-content: space-between;
    padding: 0;
    background-color: #373c41;
    padding:0px 20px;
  }

  .head_left{
    color: #fff;

  }

  .head_left img{
    vertical-align: middle;
  }

  .head_left span{
    vertical-align: middle;
    padding-left: 20px;
  }

  .head_right{
    line-height: 60px;    
  }

  .el-aside{
    background-color: #323744;
  }

  .menuitem{
    padding-left: 10px;
  }

  .el-menu{
    border-right: none;
  }

  .zhedie{
    background-color: #485164;
    height: 30px;
    line-height: 30px;
    text-align: center;
    color: #fff;
    letter-spacing: 0.2em;
    cursor: pointer;
  }
</style>
